<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">



  
  
    
    
  <script src="/lib/pace/pace.min.js?v=1.0.2"></script>
  <link href="/lib/pace/pace-theme-fill-left.min.css?v=1.0.2" rel="stylesheet">







<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="NexT主题踩坑," />





  <link rel="alternate" href="/atom.xml" title="我的笔记本" type="application/atom+xml" />






<meta name="description" content="导读Next主题确实是好用，但是中间还是有太多太多的坑，差点没把自己摔死。这个博客记录了完成背景图片轮播的博客，喜欢折腾的同学可以看看，这方面对CSS3的要求略微有点高。">
<meta property="og:type" content="article">
<meta property="og:title" content="Hexo设置背景图片轮播效果">
<meta property="og:url" content="https://sakebow.github.io/2020/01/29/hexo/hexo%E4%BF%AE%E6%94%B9%E8%83%8C%E6%99%AF%E5%9B%BE%E7%89%87/index.html">
<meta property="og:site_name" content="我的笔记本">
<meta property="og:description" content="导读Next主题确实是好用，但是中间还是有太多太多的坑，差点没把自己摔死。这个博客记录了完成背景图片轮播的博客，喜欢折腾的同学可以看看，这方面对CSS3的要求略微有点高。">
<meta property="og:image" content="https://sakebow.gitee.io/images/background/poi.png">
<meta property="og:image" content="https://sakebow.gitee.io/images/hexo-change-background-image/screenshots/1.png">
<meta property="article:published_time" content="2020-01-29T08:41:00.000Z">
<meta property="article:modified_time" content="2020-11-12T14:22:28.000Z">
<meta property="article:author" content="sakebow">
<meta property="article:tag" content="NexT主题踩坑">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://sakebow.gitee.io/images/background/poi.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":true,"scrollpercent":true,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://sakebow.github.io/2020/01/29/hexo/hexo修改背景图片/"/>



<meta name="google-site-verification" content="gmKmVpWaqN85ipDFNNCd2AweYJjcTFrVxCKCy36wueo" />
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?1d2c90caa02c073d8ebaa116ab3027fb";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>


  <title>Hexo设置背景图片轮播效果 | 我的笔记本</title>
  








  
  <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
  <script type="text/javascript" src="/js/src/custom.js"></script>
  
<meta name="generator" content="Hexo 4.2.1"></head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>
	
	<a href="https://github.com/sakebow" target="_blank" rel="noopener" class="github-corner" aria-label="View source on GitHub">
	  <svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"
	    style="fill:#64CEAA; color:#fff; position: fixed; top: 0; border: 0; right: 0; z-index: 999;">
	    <path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
		<path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2"
		  fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path>
		<path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z"
		  fill="currentColor" class="octo-body"></path>
	  </svg>
	</a>
	<style>
	  .github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}
	  @keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}
	  @media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}
	</style>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">我的笔记本</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">一只干什么都会失败但是很不想放弃的科研狗</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://sakebow.github.io/2020/01/29/hexo/hexo%E4%BF%AE%E6%94%B9%E8%83%8C%E6%99%AF%E5%9B%BE%E7%89%87/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="sakebow">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/icon/UN.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="我的笔记本">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Hexo设置背景图片轮播效果</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2020-01-29T16:41:00+08:00">
                2020-01-29
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Hexo/" itemprop="url" rel="index">
                    <span itemprop="name">Hexo</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2020/01/29/hexo/hexo%E4%BF%AE%E6%94%B9%E8%83%8C%E6%99%AF%E5%9B%BE%E7%89%87/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count gitment-comments-count" data-xid="/2020/01/29/hexo/hexo%E4%BF%AE%E6%94%B9%E8%83%8C%E6%99%AF%E5%9B%BE%E7%89%87/" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv"><i class="fa fa-file-o"></i>
            <span class="busuanzi-value" id="busuanzi_value_page_pv" ></span>
            </span>
          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  4k字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  15分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="导读"><a href="#导读" class="headerlink" title="导读"></a>导读</h2><p><strong>Next主题确实是好用，但是中间还是有太多太多的坑，差点没把自己摔死。这个博客记录了完成背景图片轮播的博客，喜欢折腾的同学可以看看，这方面对CSS3的要求略微有点高。</strong><br><a id="more"></a></p>
<p><a href="https://hexo.io" target="_blank" rel="noopener">Hexo</a>的<a href="https://github.com/theme-next" target="_blank" rel="noopener">NexT</a>主题非常简约，个性化调整也非常方便。在这里就给大家介绍Hexo的背景图片轮播的制作方法。</p>
<h2 id="尴尬的开发条件"><a href="#尴尬的开发条件" class="headerlink" title="尴尬的开发条件"></a>尴尬的开发条件</h2><p>由于我还很菜，再加上电脑卡顿严重，有时候所有方法全部试了一遍都没有效果，重新创建一个工程就好了，也有时候重启就好了。这个背景图片轮播就是<strong>除了吃饭连续调了36个小时</strong>，<strong>最后重新新建一个项目就好了</strong>。这样的情况下调bug简直就是折磨。所以我基本上就用最小幅度的修改来保证需求的实现。</p>
<p>好了，来看看从入门到入土的全过程吧。我使用的是<code>WebStorm</code>作为<code>IDE</code>，其中内置的终端是可以操作的。如果没有<code>WebStorm</code>的话，可以使用<code>git</code>的<code>Windows</code>桌面版客户端自带的终端，即<code>Git Bash</code>，是个非常不错的终端，个人非常喜欢<code>Vim</code>风格。但是<code>Windows</code><strong>自带的终端是不可以操作</strong><code>Hexo</code>的，连<code>PowerShell</code><strong>的管理员模式也不可以</strong>，这一点还请注意。</p>
<h2 id="开发条件更新（2020年6月27日）"><a href="#开发条件更新（2020年6月27日）" class="headerlink" title="开发条件更新（2020年6月27日）"></a>开发条件更新（2020年6月27日）</h2><p>弱弱电脑泡水了，光荣牺牲。现在换了强强电脑，也就是现在的台式机，并且改用内存占用更少的<code>VScode</code>配合<code>Git Bash</code>分别完成<strong>编辑</strong>和<strong>部署</strong>。<code>VScode</code>中安装的插件就是<code>markdown-all-in-one</code>、<code>GitLens</code>和<code>Language-Stylus</code>，分别完成<code>markdown编辑</code>、<code>GitHub部署</code>和<code>Stylus样式表</code>三个部分。很可惜的是<code>VScode</code>自带的终端不能代替<code>Git Bash</code>，就有点不太方便。其他的都还可以。</p>
<h2 id="确定背景图片"><a href="#确定背景图片" class="headerlink" title="确定背景图片"></a>确定背景图片</h2><p>我们先找好一个背景图片，就你啦。<em><del>没错，博主是个不折不扣的死肥宅</del></em></p>
<p><img src="https://sakebow.gitee.io/images/background/poi.png" alt="夕立"></p>
<p>然后把他放在背景图片中。由于夕立的图片从左到右对比度差异比较大，我准备加上透明度。透明度确实有很多种方法，我选了个对模板改动最小的方法：<code>after伪类</code>。于是，<strong>噩梦开始了</strong>。</p>
<h2 id="写入样式表"><a href="#写入样式表" class="headerlink" title="写入样式表"></a>写入样式表</h2><p>在NexT模板里面，样式表大多是用styl文件存储的，简单地说，它是一种新语言，叫Stylus语言，基于nodejs，非常强大，补足了CSS3的许多缺点。</p>
<p>接着我们找到NexT模板中给我们预留的自定义样式文件中，也就是根目录下的：<code>/themes/next/source/css/_custom/custom.styl</code>，打开发现是个空的。</p>
<p>好了，写下我们的代码：（<em>由于里面包含keyframe，就直接用CSS3全部写完了，没用上stylus</em>）</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* </span></span><br><span class="line"><span class="comment"> * 在上层的body什么都不要写，因为body加上透明度opacity后文字也变得透明了</span></span><br><span class="line"><span class="comment"> * 于是所有的东西全部写在伪类，这里只保留最低限度的：层数（防遮盖）、位置（相对伪类的位置）</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="selector-tag">body</span> &#123;</span><br><span class="line">  <span class="attribute">position </span>: relative;</span><br><span class="line">  <span class="attribute">z-index </span>: <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/* </span></span><br><span class="line"><span class="comment"> * 在伪类中加上所有的属性</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="selector-tag">body</span><span class="selector-pseudo">:after</span> &#123;</span><br><span class="line">  <span class="attribute">content </span>: <span class="string">''</span>;                 <span class="comment">/* 伪类需要有内容，否则会变成0*0，无法显示效果 */</span></span><br><span class="line">  <span class="attribute">width</span>: <span class="number">100%</span>;                  <span class="comment">/* 宽度拉满 */</span></span><br><span class="line">  <span class="attribute">height</span>: <span class="number">100%</span>;                 <span class="comment">/* 高度拉满 */</span></span><br><span class="line">  <span class="attribute">background-size</span>: cover;       <span class="comment">/* 背景图片铺满整个容器 */</span></span><br><span class="line">  <span class="attribute">background-repeat</span>: no-repeat; <span class="comment">/* 不要重复 */</span></span><br><span class="line">  <span class="attribute">opacity</span>: <span class="number">0.5</span>;                 <span class="comment">/* 透明度为50% */</span></span><br><span class="line">  <span class="attribute">-moz-opacity</span>: <span class="number">0.5</span>;            <span class="comment">/* 火狐浏览器的透明度设置 */</span></span><br><span class="line">  <span class="attribute">-khtml-opacity</span>: <span class="number">0.5</span>;          <span class="comment">/* safari浏览器的透明度设置，它使用了KDE的KHTML作为内核 */</span></span><br><span class="line">  <span class="attribute">position</span>: fixed;              <span class="comment">/* 位置设为固定，否则往下滑背景图片就滑没了 */</span></span><br><span class="line">  <span class="attribute">z-index</span>: -<span class="number">1</span>;                  <span class="comment">/* 防遮罩 */</span></span><br><span class="line">  <span class="attribute">top</span>: <span class="number">0</span>;                       <span class="comment">/* y坐标抵到浏览器顶部 */</span></span><br><span class="line">  <span class="attribute">left</span>: <span class="number">0</span>;                      <span class="comment">/* x坐标抵到浏览器左侧 */</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>于是，就有了这样的效果：</p>
<p><img src="https://sakebow.gitee.io/images/hexo-change-background-image/screenshots/1.png" alt="演示效果图1"></p>
<p>看着好像还行？</p>
<h2 id="编写js脚本"><a href="#编写js脚本" class="headerlink" title="编写js脚本"></a>编写js脚本</h2><p>找到根目录下的<code>/themes/next/source/js/src</code>，在其中<strong>新建</strong>一个<code>js</code>文件。这里并没有给我们预留一个空文件，那就自己新建好了。我新建了<code>custom.js</code>文件。</p>
<p><strong>严重警告</strong>：下面这个例子是我第一次的尝试，是<strong>错误的</strong>！</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 将所有的路径写下来</span></span><br><span class="line"><span class="keyword">let</span> imgUrl = [</span><br><span class="line">  <span class="string">'/images/background/poi.png'</span>, <span class="comment">// 舰娘夕立</span></span><br><span class="line">  <span class="string">'/images/background/touhou-red.jpg'</span> <span class="comment">// 东方红魔馆</span></span><br><span class="line">];</span><br><span class="line"><span class="comment">// 这里let类型是ECMA script6的特性</span></span><br><span class="line"><span class="comment">// 可以让我们把这个变量仅限于大括号内，可以组织非法访问带来的莫名其妙的问题</span></span><br><span class="line"><span class="keyword">let</span> imgIndex = <span class="number">0</span>; <span class="comment">// 设置imgIndex来选择imgUrl中的字符串</span></span><br><span class="line"><span class="comment">// 设置计时器，每8秒换一次图片</span></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 这里用setInterval函数</span></span><br><span class="line"><span class="comment"> * 传递2个参数</span></span><br><span class="line"><span class="comment"> *   一个是执行的事件，也就是函数对象</span></span><br><span class="line"><span class="comment"> *       可以写好了再把方法名传进来，也可以直接在这里定义</span></span><br><span class="line"><span class="comment"> *   还有一个是中间等待的时间，也就是多长时间执行一次</span></span><br><span class="line"><span class="comment"> * 返回一个定时器对象，方便在需要删除该定时器的时候直接引用</span></span><br><span class="line"><span class="comment"> * 如果不删除定时器，这个定时器就会一直进行下去</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">let</span> interval = setInterval(<span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">  <span class="comment">// 1、获取需要变更的元素</span></span><br><span class="line">  <span class="comment">// 2、变更url</span></span><br><span class="line">  $(<span class="string">'body:after'</span>).css(<span class="string">"background-image"</span>, <span class="string">"url('"</span> + imgUrl[imgIndex] + <span class="string">"')"</span>);</span><br><span class="line">  <span class="comment">// 3、imgIndex自增，越界归零，也就是循环播放效果</span></span><br><span class="line">  (imgIndex === imgUrl.length) ? (imgIndex = <span class="number">0</span>) : (imgIndex++)</span><br><span class="line">  <span class="comment">// 这个是唯一的三元运算符，可以叫做冒号运算符</span></span><br><span class="line">  <span class="comment">// 如果满足问号前的条件，就执行第二个括号里面的语句，否则执行第三个括号里面的语句。</span></span><br><span class="line">  <span class="comment">// 由于运算符有规定的优先顺序，所以这里不加括号也是完全OK的，只是为了让大家看得清楚才加上的</span></span><br><span class="line">&#125;, <span class="number">8000</span>);</span><br></pre></td></tr></table></figure>
<p>最后，找到根目录下的<code>/themes/next/layout/_custom/header.swig</code>，这是个空文件。在里面引入jQuery和我们刚刚完成的js文件。</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- 这里是用的bootcdn中的jQuery镜像，可以加载得稍微快一点点，这一点点差别人类感觉不到就是了。 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">"https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- 同样的，由于实在next模板内做的修改，src="/"访问的其实是根目录下的/themes/next，所以从/js/开始 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">"text/javascript"</span> <span class="attr">src</span>=<span class="string">"/js/src/custom.js"</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br></pre></td></tr></table></figure>
<blockquote>
<p><strong>科普：</strong><code>swig</code>简单的说就是一种超级强大的工具，基本上很多语言都支持，甚至可以用于汇编开发中。</p>
</blockquote>
<p>好的！到这里就结束了！在WebStorm下方的Terminal（汉化了的同学这里叫做“终端”）输入hexo server，敲下回车就可以运行了。终端会弹出一大堆东西，其中有一句话是：”localhost:4000/“，点击就会自动呼出浏览器运行结果。</p>
<blockquote>
<p><strong>P.S.</strong> 会玩的同学可以在淘宝上购买一个超大号的回车键，每当这个时候就可以郑重地像按起爆器一样按下去，非常有仪式感。</p>
</blockquote>
<h3 id="发现问题"><a href="#发现问题" class="headerlink" title="发现问题"></a>发现问题</h3><p>然后，什么效果都没有。</p>
<p><strong>我慌了</strong>。</p>
<p>一开始我以为是url拼接的问题，调了很久很久，一直没成功。直到最后，我才明白：<strong>伪类after不可以被选中</strong>。</p>
<p><strong>全部木大啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊(╯‵□′)╯︵┻━┻</strong></p>
<p>上网一查，发现有一些方法，比如append一个新的style标签，这样子很难看清楚，也不容易编写。最后还是决定：<strong>把每一个图片定义成一个单独的CSS样式的类，然后每隔一段时间让body换个类</strong>。听着不难？试试吧。</p>
<h3 id="再次修改"><a href="#再次修改" class="headerlink" title="再次修改"></a>再次修改</h3><p><strong>还是严重警告</strong>：下面的<code>CSS</code>部分是第二次尝试，还是略微有一点点问题，<strong>下方注释会标记有问题的地方</strong></p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-tag">body</span>, <span class="selector-class">.pekora</span>, <span class="selector-class">.beaten</span>, <span class="selector-class">.collection</span>, <span class="selector-class">.touhou-red</span>, <span class="selector-class">.bang</span>, <span class="selector-class">.succubus</span>, <span class="selector-class">.poi</span> &#123;</span><br><span class="line">  <span class="attribute">position </span>: relative;</span><br><span class="line">  <span class="attribute">z-index </span>: <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="selector-tag">body</span><span class="selector-pseudo">:after</span>,</span><br><span class="line"><span class="selector-class">.pekora</span><span class="selector-pseudo">:after</span>, <span class="selector-class">.touhou-red</span><span class="selector-pseudo">:after</span>, <span class="selector-class">.beaten</span><span class="selector-pseudo">:after</span>, <span class="selector-class">.collection</span><span class="selector-pseudo">:after</span>, <span class="selector-class">.bang</span><span class="selector-pseudo">:after</span>, <span class="selector-class">.succubus</span><span class="selector-pseudo">:after</span>, <span class="selector-class">.poi</span><span class="selector-pseudo">:after</span> &#123;</span><br><span class="line">  <span class="attribute">content </span>: <span class="string">''</span>;</span><br><span class="line">  <span class="attribute">width</span>: <span class="number">100%</span>;</span><br><span class="line">  <span class="attribute">height</span>: <span class="number">100%</span>;</span><br><span class="line">  <span class="attribute">background-size</span>: cover;</span><br><span class="line">  <span class="attribute">background-repeat</span>: no-repeat;</span><br><span class="line">  <span class="attribute">opacity</span>: <span class="number">0</span>;</span><br><span class="line">  <span class="attribute">-moz-opacity</span>:<span class="number">0</span>;</span><br><span class="line">  <span class="attribute">-khtml-opacity</span>: <span class="number">0</span>;</span><br><span class="line">  <span class="attribute">position</span>: fixed;</span><br><span class="line">  <span class="attribute">z-index</span>: -<span class="number">1</span>;</span><br><span class="line">  <span class="attribute">top</span>: <span class="number">0</span>;</span><br><span class="line">  <span class="attribute">left</span>: <span class="number">0</span>;</span><br><span class="line">  <span class="comment">/* 加上动画 */</span></span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 我给animation传入的3个值分别是：</span></span><br><span class="line"><span class="comment">   *   - 动画名称 - bg-scale</span></span><br><span class="line"><span class="comment">   *   - 延迟时间 - 动画会持续8秒</span></span><br><span class="line"><span class="comment">   *   - 执行次数 - 无限执行：infinite</span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  <span class="attribute">animation </span>: bg-scale <span class="number">8s</span> infinite;</span><br><span class="line">  <span class="attribute">-webkit-animation </span>: bg-scale <span class="number">8s</span> infinite;</span><br><span class="line">  <span class="attribute">-moz-animation </span>: bg-scale <span class="number">8s</span> infinite;</span><br><span class="line">  <span class="attribute">-o-animation </span>: bg-scale <span class="number">8s</span> infinite;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 大家完全可以复制粘贴，注意这下面的url要换成自己的图片路径。</span></span><br><span class="line"><span class="comment"> * 例如我将图片存在了根目录下的/themes/next/source/images/background/里面，所有的url就都这样配置了</span></span><br><span class="line"><span class="comment"> * 需要说明的是：这是在next模板中配置的，所以url("/")所访问的根目录是/themes/next/source/</span></span><br><span class="line"><span class="comment"> * 所以url就直接是省略了前面的，从/images/开始</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="comment">/* hololive所属vtuber三期生：pekora，嚣张的兔子 */</span></span><br><span class="line"><span class="selector-class">.pekora</span><span class="selector-pseudo">:after</span> &#123;</span><br><span class="line">  <span class="attribute">background-image </span>: <span class="built_in">url</span>(<span class="string">"/images/background/pekora.jpg"</span>);</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/* 东方红魔馆 */</span></span><br><span class="line"><span class="comment">/* 把body:after也设置了就是为了初始化</span></span><br><span class="line"><span class="comment"> * 这样一开始就是这个图片作为背景，</span></span><br><span class="line"><span class="comment"> * 也算是不动用重要模板文件的最小程度修改</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="selector-tag">body</span><span class="selector-pseudo">:after</span>, <span class="selector-class">.touhou-red</span><span class="selector-pseudo">:after</span> &#123;</span><br><span class="line">  <span class="attribute">background-image </span>: <span class="built_in">url</span>(<span class="string">"/images/background/touhou-red.jpg"</span>);</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/* 将R16的百合图片中，攻的一方配上“现实”，受的一方配上“我”。看到这张图片的时候我的心情非常复杂 */</span></span><br><span class="line"><span class="selector-class">.beaten</span><span class="selector-pseudo">:after</span> &#123;</span><br><span class="line">  <span class="attribute">background-image </span>: <span class="built_in">url</span>(<span class="string">"/images/background/beaten.jpg"</span>);</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/* 澡堂中的舰娘们 */</span></span><br><span class="line"><span class="selector-class">.collection</span><span class="selector-pseudo">:after</span> &#123;</span><br><span class="line">  <span class="attribute">background-image </span>: <span class="built_in">url</span>(<span class="string">"/images/background/collection.jpg"</span>);</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/* 偶像大师（圣诞限定版） */</span></span><br><span class="line"><span class="selector-class">.bang</span><span class="selector-pseudo">:after</span> &#123;</span><br><span class="line">  <span class="attribute">background-image </span>: <span class="built_in">url</span>(<span class="string">"/images/background/bang.jpg"</span>);</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/* 四只比基尼魅魔，是《魅魔和社畜》的作者所作，没有下海（一直在反复横跳就是了），不过老师的狗粮真的很美味 */</span></span><br><span class="line"><span class="selector-class">.succubus</span><span class="selector-pseudo">:after</span> &#123;</span><br><span class="line">  <span class="attribute">background-image </span>: <span class="built_in">url</span>(<span class="string">"/images/background/succubus.jpg"</span>);</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/* 舰娘夕立 */</span></span><br><span class="line"><span class="selector-class">.poi</span><span class="selector-pseudo">:after</span> &#123;</span><br><span class="line">  <span class="attribute">background-image </span>: <span class="built_in">url</span>(<span class="string">"/images/background/poi.png"</span>);</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/* 最后再加上切换的动画 */</span></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 这是一个叫做bg-scale的动画</span></span><br><span class="line"><span class="comment"> * 其实原本是有scale这个缩放的动作的</span></span><br><span class="line"><span class="comment"> * 但是违和感太强烈了删掉了</span></span><br><span class="line"><span class="comment"> * 结果这个莫名其妙的名字没改</span></span><br><span class="line"><span class="comment"> * 因为影响不大就算了吧！诶嘿~⭐</span></span><br><span class="line"><span class="comment"> * 大家可以在这其中加入自定义的动作</span></span><br><span class="line"><span class="comment"> * 尤其注意scale（缩放）和translate（平移）混用的时候scale应当在前面</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> *  注意：这个动画设置略微有一点点误差。</span></span><br><span class="line"><span class="comment"> *       后面有修改版本，请不要复制这里的动画设置</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">@keyframes</span> bg-scale &#123;</span><br><span class="line">  <span class="comment">/* 最开始的状态 */</span></span><br><span class="line">  0% &#123;</span><br><span class="line">    <span class="attribute">opacity </span>: <span class="number">0</span>;</span><br><span class="line">    <span class="attribute">transform </span>: <span class="built_in">translateY</span>(-<span class="number">3%</span>) ;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 经历1/5的时间到这一步</span></span><br><span class="line"><span class="comment">   * 完成的事件：</span></span><br><span class="line"><span class="comment">   *   - 透明度增加到50%</span></span><br><span class="line"><span class="comment">   *   - 从上方3%的地方移到了正中间（浏览器y轴朝下）</span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  20% &#123;</span><br><span class="line">    <span class="attribute">opacity </span>: <span class="number">50%</span>;</span><br><span class="line">    <span class="attribute">transform</span>: <span class="built_in">translateY</span>(<span class="number">0</span>);</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 经历3/5的时间到这一步</span></span><br><span class="line"><span class="comment">     * 完成的事件：</span></span><br><span class="line"><span class="comment">     *   - 什么都没变</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">  80% &#123;</span><br><span class="line">    <span class="attribute">opacity </span>: <span class="number">50%</span>;</span><br><span class="line">    <span class="attribute">transform</span>: <span class="built_in">translateY</span>(<span class="number">0</span>);</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 最后1/5的时间到这一步</span></span><br><span class="line"><span class="comment">   * 完成的事件：</span></span><br><span class="line"><span class="comment">   *   - 透明度变为0%（完全看不见）</span></span><br><span class="line"><span class="comment">   *   - 从正中间平移到下方3%的地方</span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  100% &#123;</span><br><span class="line">    <span class="attribute">opacity </span>: <span class="number">0</span>;</span><br><span class="line">    <span class="attribute">transform</span>: <span class="built_in">translateY</span>(<span class="number">3%</span>);</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/* 下面都是针对各种浏览器的特化，意义是一样的 */</span></span><br><span class="line"><span class="keyword">@-webkit-keyframes</span> bg-scale&#123;</span><br><span class="line">  0% &#123;</span><br><span class="line">    <span class="attribute">opacity </span>: <span class="number">0</span>;</span><br><span class="line">    <span class="attribute">-webkit-transform </span>: <span class="built_in">translateY</span>(-<span class="number">3%</span>) ;</span><br><span class="line">  &#125;</span><br><span class="line">  20% &#123;</span><br><span class="line">    <span class="attribute">opacity </span>: <span class="number">50%</span>;</span><br><span class="line">    <span class="attribute">-webkit-transform</span>: <span class="built_in">translateY</span>(<span class="number">0</span>);</span><br><span class="line">  &#125;</span><br><span class="line">  80% &#123;</span><br><span class="line">    <span class="attribute">opacity </span>: <span class="number">50%</span>;</span><br><span class="line">    <span class="attribute">-webkit-transform</span>: <span class="built_in">translateY</span>(<span class="number">0</span>);</span><br><span class="line">  &#125;</span><br><span class="line">  100% &#123;</span><br><span class="line">    <span class="attribute">opacity </span>: <span class="number">0</span>;</span><br><span class="line">    <span class="attribute">-webkit-transform</span>: <span class="built_in">translateY</span>(<span class="number">3%</span>);</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">@-moz-keyframes</span> bg-scale&#123;</span><br><span class="line">  0% &#123;</span><br><span class="line">    <span class="attribute">-moz-opacity </span>: <span class="number">0</span>;</span><br><span class="line">    <span class="attribute">-moz-transform </span>: <span class="built_in">translateY</span>(-<span class="number">3%</span>) ;</span><br><span class="line">  &#125;</span><br><span class="line">  20% &#123;</span><br><span class="line">    <span class="attribute">-moz-opacity </span>: <span class="number">50%</span>;</span><br><span class="line">    <span class="attribute">-moz-transform</span>: <span class="built_in">translateY</span>(<span class="number">0</span>);</span><br><span class="line">  &#125;</span><br><span class="line">  80% &#123;</span><br><span class="line">    <span class="attribute">-moz-opacity </span>: <span class="number">50%</span>;</span><br><span class="line">    <span class="attribute">-moz-transform</span>: <span class="built_in">translateY</span>(<span class="number">0</span>);</span><br><span class="line">  &#125;</span><br><span class="line">  100% &#123;</span><br><span class="line">    <span class="attribute">-moz-opacity </span>: <span class="number">0</span>;</span><br><span class="line">    <span class="attribute">-moz-transform</span>: <span class="built_in">translateY</span>(<span class="number">3%</span>);</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">@-o-keyframes</span> bg-scale&#123;</span><br><span class="line">  0% &#123;</span><br><span class="line">    <span class="attribute">opacity </span>: <span class="number">0</span>;</span><br><span class="line">    <span class="attribute">-o-transform </span>: <span class="built_in">translateY</span>(-<span class="number">3%</span>) ;</span><br><span class="line">  &#125;</span><br><span class="line">  20% &#123;</span><br><span class="line">    <span class="attribute">opacity </span>: <span class="number">50%</span>;</span><br><span class="line">    <span class="attribute">-o-transform</span>: <span class="built_in">translateY</span>(<span class="number">0</span>);</span><br><span class="line">  &#125;</span><br><span class="line">  80% &#123;</span><br><span class="line">    <span class="attribute">opacity </span>: <span class="number">50%</span>;</span><br><span class="line">    <span class="attribute">-o-transform</span>: <span class="built_in">translateY</span>(<span class="number">0</span>);</span><br><span class="line">  &#125;</span><br><span class="line">  100% &#123;</span><br><span class="line">    <span class="attribute">opacity </span>: <span class="number">0</span>;</span><br><span class="line">    <span class="attribute">-o-transform</span>: <span class="built_in">translateY</span>(<span class="number">3%</span>);</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>终于，<strong>背景动了</strong>。虽然只是不停的重复同一张图片，但是那种感动、懊悔和愤慨，久久地回荡在胸腔中。最终，爆发了出来：<strong>wdnmd</strong>！</p>
<h3 id="最后加上js脚本（custom-js）"><a href="#最后加上js脚本（custom-js）" class="headerlink" title="最后加上js脚本（custom.js）"></a>最后加上js脚本（custom.js）</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 这是jQuery的写法，意思是一打开这页面就这么做</span></span><br><span class="line">$(<span class="built_in">document</span>).ready(<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">  <span class="comment">// 先准备好和类名一样的字符串数组</span></span><br><span class="line">  <span class="keyword">let</span> IMG_CLASS = [<span class="string">"touhou-red"</span>, <span class="string">"poi"</span>, <span class="string">"beaten"</span>, <span class="string">"collection"</span>, <span class="string">"pekora"</span>, <span class="string">"succubus"</span>, <span class="string">"bang"</span>];</span><br><span class="line">  <span class="comment">// 再准备一个索引</span></span><br><span class="line">  <span class="keyword">let</span> imgIndex = <span class="number">0</span>;</span><br><span class="line">  <span class="comment">/** 还需要一个计时器</span></span><br><span class="line"><span class="comment">   * 这个计时器传入了两个参数</span></span><br><span class="line"><span class="comment">   *   - 第一个表示需要重复的动作</span></span><br><span class="line"><span class="comment">   *   - 第二个表示下一次动作的延迟时间</span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  <span class="keyword">let</span> interval = setInterval(<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="comment">// 删除上一个类名（如果本身就没有这个类名也不会报错）</span></span><br><span class="line">    $(<span class="string">"body"</span>).removeClass(IMG_CLASS[imgIndex]);</span><br><span class="line">    <span class="comment">// 索引 + 1</span></span><br><span class="line">    imgIndex++;</span><br><span class="line">    <span class="comment">// 当越界的时候归零，变成循环展示图片</span></span><br><span class="line">    <span class="keyword">if</span> (imgIndex == IMG_CLASS.length) &#123;</span><br><span class="line">      imgIndex = <span class="number">0</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 加上当前索引所指向的类名</span></span><br><span class="line">    $(<span class="string">"body"</span>).addClass(IMG_CLASS[imgIndex]);</span><br><span class="line">  &#125;, <span class="number">8000</span>); <span class="comment">// 每8000毫秒，也就是8秒执行一次</span></span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>
<h3 id="希望之花"><a href="#希望之花" class="headerlink" title="希望之花"></a>希望之花</h3><p>知道这个梗的人应该都明白，“不要停下来啊！”代表的是什么意思。没错，还远远没有结束。<strong>心态崩坏第二弹</strong>：<strong>js代码本身存在的bug</strong></p>
<p>JavaScript代码是运行在客户端的。所以它代表了一个问题：客户的电脑情况很大程度上决定了代码的成果。比如：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- 引入代码 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">link</span> <span class="attr">rel</span>=<span class="string">"stylesheet"</span> <span class="attr">href</span>=<span class="string">"//cdn.bootcss.com/highlight.js/9.6.0/styles/github.min.css"</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>乍一看没什么问题。<strong>可是这天你断网了</strong>。码农好好的坐在公司里调bug，一口大锅就这么扣在了他头上。</p>
<p>我所遇到的情况正是如此。js里写好了8000ms的延迟，CSS样式文件里也清清楚楚写了8s，但是就是有误差，这个误差不是别的原因，就是由每个人的电脑性能不同决定的。新的图片展示之前，旧的图片会很明显的闪一下。就这么一点点的误差展现了这么刺眼的效果。</p>
<p>求求你让我下班吧……orz</p>
<h3 id="暴力解决"><a href="#暴力解决" class="headerlink" title="暴力解决"></a>暴力解决</h3><p>我放弃了思考，如果会闪的话，那就是说，在js执行之前，keyframe动画就已经开始了执行下一个动画。那么，眼不见为净，就让这短暂的几帧动画看不到就好了！</p>
<p>于是，keyframe的最终版：</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 用这一段代码替换之前提到的的keyframe</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">@keyframes</span> bg-scale &#123;</span><br><span class="line">  0% &#123;</span><br><span class="line">    <span class="attribute">opacity </span>: <span class="number">0</span>;</span><br><span class="line">    <span class="attribute">transform </span>: <span class="built_in">translateY</span>(-<span class="number">3%</span>) ;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 在这1/20的时间里什么都不做</span></span><br><span class="line"><span class="comment">   * 保持透明度为0（什么都看不见的白板）</span></span><br><span class="line"><span class="comment">   * 于是造成了小于1秒的空白背景</span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  5% &#123;</span><br><span class="line">    <span class="attribute">opacity </span>: <span class="number">0</span>;</span><br><span class="line">    <span class="attribute">transform </span>: <span class="built_in">translateY</span>(-<span class="number">3%</span>) ;</span><br><span class="line">  &#125;</span><br><span class="line">  </span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 紧接着，这1/5的时间里完成了：</span></span><br><span class="line"><span class="comment">   *   - 透明度从0变为50</span></span><br><span class="line"><span class="comment">   *   - 从上方3%的位置移到正中间</span></span><br><span class="line"><span class="comment">   * 所以，之前小于1秒的空白背景就在忍受范围内了！</span></span><br><span class="line"><span class="comment">   * 我可真是个靓仔</span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  25% &#123;</span><br><span class="line">    <span class="attribute">opacity </span>: <span class="number">50%</span>;</span><br><span class="line">    <span class="attribute">transform</span>: <span class="built_in">translateY</span>(<span class="number">0</span>);</span><br><span class="line">  &#125;</span><br><span class="line">  80% &#123;</span><br><span class="line">    <span class="attribute">opacity </span>: <span class="number">50%</span>;</span><br><span class="line">    <span class="attribute">transform</span>: <span class="built_in">translateY</span>(<span class="number">0</span>);</span><br><span class="line">  &#125;</span><br><span class="line">  100% &#123;</span><br><span class="line">    <span class="attribute">opacity </span>: <span class="number">0</span>;</span><br><span class="line">    <span class="attribute">transform</span>: <span class="built_in">translateY</span>(<span class="number">3%</span>);</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">@-webkit-keyframes</span> bg-scale&#123;</span><br><span class="line">  0% &#123;</span><br><span class="line">    <span class="attribute">opacity </span>: <span class="number">0</span>;</span><br><span class="line">    <span class="attribute">-webkit-transform </span>: <span class="built_in">translateY</span>(-<span class="number">3%</span>) ;</span><br><span class="line">  &#125;</span><br><span class="line">  5% &#123;</span><br><span class="line">    <span class="attribute">opacity </span>: <span class="number">0</span>;</span><br><span class="line">    <span class="attribute">-webkit-transform </span>: <span class="built_in">translateY</span>(-<span class="number">3%</span>) ;</span><br><span class="line">  &#125;</span><br><span class="line">  25% &#123;</span><br><span class="line">    <span class="attribute">opacity </span>: <span class="number">50%</span>;</span><br><span class="line">    <span class="attribute">-webkit-transform</span>: <span class="built_in">translateY</span>(<span class="number">0</span>);</span><br><span class="line">  &#125;</span><br><span class="line">  80% &#123;</span><br><span class="line">    <span class="attribute">opacity </span>: <span class="number">50%</span>;</span><br><span class="line">    <span class="attribute">-webkit-transform</span>: <span class="built_in">translateY</span>(<span class="number">0</span>);</span><br><span class="line">  &#125;</span><br><span class="line">  100% &#123;</span><br><span class="line">    <span class="attribute">opacity </span>: <span class="number">0</span>;</span><br><span class="line">    <span class="attribute">-webkit-transform</span>: <span class="built_in">translateY</span>(<span class="number">3%</span>);</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">@-moz-keyframes</span> bg-scale&#123;</span><br><span class="line">  0% &#123;</span><br><span class="line">    <span class="attribute">-moz-opacity </span>: <span class="number">0</span>;</span><br><span class="line">    <span class="attribute">-moz-transform </span>: <span class="built_in">translateY</span>(-<span class="number">3%</span>) ;</span><br><span class="line">  &#125;</span><br><span class="line">  5% &#123;</span><br><span class="line">    <span class="attribute">-moz-opacity </span>: <span class="number">0</span>;</span><br><span class="line">    <span class="attribute">-moz-transform </span>: <span class="built_in">translateY</span>(-<span class="number">3%</span>) ;</span><br><span class="line">  &#125;</span><br><span class="line">  25% &#123;</span><br><span class="line">    <span class="attribute">-moz-opacity </span>: <span class="number">50%</span>;</span><br><span class="line">    <span class="attribute">-moz-transform</span>: <span class="built_in">translateY</span>(<span class="number">0</span>);</span><br><span class="line">  &#125;</span><br><span class="line">  80% &#123;</span><br><span class="line">    <span class="attribute">-moz-opacity </span>: <span class="number">50%</span>;</span><br><span class="line">    <span class="attribute">-moz-transform</span>: <span class="built_in">translateY</span>(<span class="number">0</span>);</span><br><span class="line">  &#125;</span><br><span class="line">  100% &#123;</span><br><span class="line">    <span class="attribute">-moz-opacity </span>: <span class="number">0</span>;</span><br><span class="line">    <span class="attribute">-moz-transform</span>: <span class="built_in">translateY</span>(<span class="number">3%</span>);</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">@-o-keyframes</span> bg-scale&#123;</span><br><span class="line">  0% &#123;</span><br><span class="line">    <span class="attribute">opacity </span>: <span class="number">0</span>;</span><br><span class="line">    <span class="attribute">-o-transform </span>: <span class="built_in">translateY</span>(-<span class="number">3%</span>) ;</span><br><span class="line">  &#125;</span><br><span class="line">  5% &#123;</span><br><span class="line">    <span class="attribute">opacity </span>: <span class="number">0</span>;</span><br><span class="line">    <span class="attribute">-o-transform </span>: <span class="built_in">translateY</span>(-<span class="number">3%</span>) ;</span><br><span class="line">  &#125;</span><br><span class="line">  25% &#123;</span><br><span class="line">    <span class="attribute">opacity </span>: <span class="number">50%</span>;</span><br><span class="line">    <span class="attribute">-o-transform</span>: <span class="built_in">translateY</span>(<span class="number">0</span>);</span><br><span class="line">  &#125;</span><br><span class="line">  80% &#123;</span><br><span class="line">    <span class="attribute">opacity </span>: <span class="number">50%</span>;</span><br><span class="line">    <span class="attribute">-o-transform</span>: <span class="built_in">translateY</span>(<span class="number">0</span>);</span><br><span class="line">  &#125;</span><br><span class="line">  100% &#123;</span><br><span class="line">    <span class="attribute">opacity </span>: <span class="number">0</span>;</span><br><span class="line">    <span class="attribute">-o-transform</span>: <span class="built_in">translateY</span>(<span class="number">3%</span>);</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>nice！<strong>下班啦</strong>！</p>
<h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><p>当然这个方法是有点问题的，比如<strong>网速慢的时候只能第一张图片无限循环</strong>；<strong>后期添加图片的时候非常的麻烦</strong>等等非常无奈的问题。但是总体效果还是非常不错的呐！</p>
<p>虽然路途坎坷，但是确实可以看出，<code>Hexo</code>的美化要是认真从前端入手一点点深入，一点点修改，就能够做出你认为最好的。正因为方法多样，所以才有如此广阔的创意模板和二次魔改，这就是<code>Hexo</code>的魅力不是吗？</p>

      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>代码滞销，救救码农</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/pay/wechatpay.png" alt="sakebow 微信支付"/>
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/pay/alipay.jpg" alt="sakebow 支付宝"/>
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    
      <div>
        <ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者：</strong>
    sakebow
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="https://sakebow.github.io/2020/01/29/hexo/hexo%E4%BF%AE%E6%94%B9%E8%83%8C%E6%99%AF%E5%9B%BE%E7%89%87/" title="Hexo设置背景图片轮播效果">https://sakebow.github.io/2020/01/29/hexo/hexo%E4%BF%AE%E6%94%B9%E8%83%8C%E6%99%AF%E5%9B%BE%E7%89%87/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>
    本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/3.0/" rel="external nofollow" target="_blank">CC BY-NC-SA 3.0</a> 许可协议。转载请注明出处！
  </li>
</ul>

      </div>
    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/NexT%E4%B8%BB%E9%A2%98%E8%B8%A9%E5%9D%91/" rel="tag"> <i class="fa fa-tag"></i> NexT主题踩坑</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2020/01/27/README/" rel="next" title="这是我的hexo博客">
                <i class="fa fa-chevron-left"></i> 这是我的hexo博客
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2020/02/02/diary/my-college-life/" rel="prev" title="大学生活总结">
                大学生活总结 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      
        <div onclick="showGitment()" id="gitment-display-button">显示 Gitment 评论</div>
        <div id="gitment-container" style="display:none"></div>
      
    </div>
	<link rel="stylesheet" href="https://imsun.github.io/gitment/style/default.css">
    <script src="https://imsun.github.io/gitment/dist/gitment.browser.js"></script>
	<script>
      var gitment = new Gitment({
        id: '<%= page.date %>',
        owner: 'sakebow',
        repo: 'git@github.com:sakebow/sakebow.github.io.git',
        oauth: {
          client_id: '5c74c5e1b67e5a5adbdf',
          client_secret: '0d352353407a32cee695d8ac619108e725919c57',
        },
      });
      gitment.render('gitment-container');
    </script>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/icon/UN.png"
                alt="sakebow" />
            
              <p class="site-author-name" itemprop="name">sakebow</p>
              <p class="site-description motion-element" itemprop="description">哪怕是狗也不想随随便便放弃看到的骨头</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/%7C%7C%20archive">
              
                  <span class="site-state-item-count">70</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">18</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">21</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/sakebow" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:sakebowljx@gmail.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://plus.google.com/sakebow" target="_blank" title="Google">
                      
                        <i class="fa fa-fw fa-google"></i>Google</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://twitter.com/sakebow" target="_blank" title="Twitter">
                      
                        <i class="fa fa-fw fa-twitter"></i>Twitter</a>
                  </span>
                
            </div>
          

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-block">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                Links
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="https://github.com/sakebow" title="Sakebow的GitHub" target="_blank">Sakebow的GitHub</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.appgofast.com" title="我喜欢的VPN" target="_blank">我喜欢的VPN</a>
                  </li>
                
              </ul>
            </div>
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#导读"><span class="nav-number">1.</span> <span class="nav-text">导读</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#尴尬的开发条件"><span class="nav-number">2.</span> <span class="nav-text">尴尬的开发条件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#开发条件更新（2020年6月27日）"><span class="nav-number">3.</span> <span class="nav-text">开发条件更新（2020年6月27日）</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#确定背景图片"><span class="nav-number">4.</span> <span class="nav-text">确定背景图片</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#写入样式表"><span class="nav-number">5.</span> <span class="nav-text">写入样式表</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#编写js脚本"><span class="nav-number">6.</span> <span class="nav-text">编写js脚本</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#发现问题"><span class="nav-number">6.1.</span> <span class="nav-text">发现问题</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#再次修改"><span class="nav-number">6.2.</span> <span class="nav-text">再次修改</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#最后加上js脚本（custom-js）"><span class="nav-number">6.3.</span> <span class="nav-text">最后加上js脚本（custom.js）</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#希望之花"><span class="nav-number">6.4.</span> <span class="nav-text">希望之花</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#暴力解决"><span class="nav-number">6.5.</span> <span class="nav-text">暴力解决</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#总结"><span class="nav-number">7.</span> <span class="nav-text">总结</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      
        <div class="back-to-top">
          <i class="fa fa-arrow-up"></i>
          
            <span id="scrollpercent"><span>0</span>%</span>
          
        </div>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Sakebow</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>




        
<div class="busuanzi-count">
  <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      
    </span>
  
</div>








        
      </div>
    </footer>

    

    
      <div id="needsharebutton-float">
        <span class="btn">
          <i class="fa fa-share-alt" aria-hidden="true"></i>
        </span>
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  







<!-- LOCAL: You can save these files to your site and update links -->
    
        
        <link rel="stylesheet" href="https://aimingoo.github.io/gitmint/style/default.css">
        <script src="https://aimingoo.github.io/gitmint/dist/gitmint.browser.js"></script>
    
<!-- END LOCAL -->

    

    
      <script type="text/javascript">
      function renderGitment(){
        var gitment = new Gitmint({
            id: window.location.pathname, 
            owner: 'sakebow',
            repo: 'git@github.com:sakebow/sakebow.github.io.git',
            
            lang: "" || navigator.language || navigator.systemLanguage || navigator.userLanguage,
            
            oauth: {
            
            
                client_secret: '0d352353407a32cee695d8ac619108e725919c57',
            
                client_id: '5c74c5e1b67e5a5adbdf'
            }});
        gitment.render('gitment-container');
      }

      
      function showGitment(){
        document.getElementById("gitment-display-button").style.display = "none";
        document.getElementById("gitment-container").style.display = "block";
        renderGitment();
      }
      
      </script>
    







  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  
  
  
  <link rel="stylesheet" href="/lib/needsharebutton/needsharebutton.css">

  
  
  <script src="/lib/needsharebutton/needsharebutton.js"></script>

  <script>
    
    
      flOptions = {};
      
          flOptions.iconStyle = "box";
      
          flOptions.boxForm = "horizontal";
      
          flOptions.position = "middleRight";
      
          flOptions.networks = "Weibo,Douban,QQZone,Twitter,Facebook";
      
      new needShareButton('#needsharebutton-float', flOptions);
    
  </script>

  

  
  
    <script type="text/x-mathjax-config">
      MathJax.Hub.Config({
        tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
        }
      });
    </script>

    <script type="text/x-mathjax-config">
      MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for (i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
        }
      });
    </script>
    <script type="text/javascript" src="https://cdn.bootcss.com/mathjax/2.7.1/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
  


  

  
 
</body>
</html>
